//
//  TBRLoginController.m
//  TBRentClient
//
//  Created by tonbright on 2018/5/4.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRLoginController.h"

@interface TBRLoginController ()

@property (weak, nonatomic) IBOutlet UITextField *tf_phone;
@property (weak, nonatomic) IBOutlet UITextField *tf_password;

@property (weak, nonatomic) IBOutlet UIButton *btn_login;
@property (weak, nonatomic) IBOutlet UIButton *btn_register;

@property (weak, nonatomic) IBOutlet UIButton *btn_forgetPW;

@end

@implementation TBRLoginController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI {
    //设置导航条
    [self setupNavItem];
    
}

- (void)setupNavItem {
    [self ISG_NavigationBarDefaultBackButtonAndNavigationTitle:@"登录"];
    [self ISG_NavigationBarWithBackButtonTitle:nil leftImageNamed:nil andAction:@selector(popToRootViewController)];
}
- (void)popToRootViewController {
    // 清除用户信息------------------
    //    [[ISGUserInfo sharedUserInfo] logout];
    [self dismissViewControllerAnimated:YES completion:nil];
    //    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (IBAction)loginBtnClick:(UIButton *)sender {
    [self.view endEditing:YES];
    NSString *account = self.tf_phone.text;
    NSString *psw = self.tf_password.text;
    //输入只能是字母和数字---------------判断账号输入的类型-------------
    NSCharacterSet *s = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"];
    s = [s invertedSet];
    NSRange r = [account rangeOfCharacterFromSet:s];
    if (r.location != NSNotFound) {
        self.noticeText = @"不能输入字母数字以外的字符";
        return;
    } else if (account.length == 0) {
        self.noticeText = @"账号不能为空";
        return;
    } else if (psw.length == 0) {
        self.noticeText = @"密码不能为空";
        return;
    } else if (psw.length < 4) {
        self.noticeText = @"密码不能小于4位";
        return;
    } else if (psw.length > 20) {
        self.noticeText = @"密码不能大于20位";
        return;
    } else {
        __weak typeof(self) weakSelf = self;
//        [NetWorkRequest postNetRequestData:@"" parmeters:@{@"username":account,@"password":psw} response:^(NSDictionary *response) {
//            if (response) {
//                [weakSelf progressHUDShowWithCompleteText:@"登录成功" isSucceed:YES];
//                //保存数据---进行一系列的操作----------
//                [self dismissViewControllerAnimated:YES completion:nil];
//            }else {
//                [weakSelf progressHUDHideImmediately];
//            }
//        } netError:^(NSError *error) {
//            [weakSelf progressHUDShowWithCompleteText:@"登录失败，请重新登录" isSucceed:NO];
//        }];
    }
}

- (IBAction)registerBtnClick:(UIButton *)sender {
    [self.view endEditing:YES];
//    RegisterViewController *vc = [RegisterViewController new];
//    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)forgetPWBtnClick:(UIButton *)sender {
}

@end
